<template>
  <div>
    <el-row justify="end" type="flex">
      <el-select v-model="currentYear" size="mini" style=" margin-right:20px">
        <el-option v-for="item in YearList" :key="item" :label="`${item}月`" :value="item" />
      </el-select>
      <el-select v-model="currentMonth" size="mini">
        <el-option v-for="item in 12 " :key="item" :label="`${item}月`" :value="item" />
      </el-select>
    </el-row>
    <el-calendar v-model="currentDate" class="flex">
      <template #dateCell="{date,data}">
        <span v-if="getDD(date)" class="rest">休</span>
        <span>{{ data.day| getDay }}</span>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  name: 'WorkCalenda',
  props: {
    startDate: {
      type: Date,
      default: new Date()
    }
  },
  filters: {
    getDay: (value) => {
      console.log(value)
      return value.split('-').at(-1)
    }
  },
  data() {
    return {
      currentYear: null,
      currentMonth: null,
      YearList: []
    }
  },
  computed: {
    currentDate() {
      return new Date(`${this.currentYear}-${this.currentMonth}-1`)
    }
  },
  created() {
    this.currentYear = this.startDate.getFullYear()
    this.currentMonth = this.startDate.getMonth() + 1
    this.YearList = Array.from(Array(11), (item, index) => {
      return this.currentYear + index - 5
    })
  },
  methods: {
    getDD(date) {
      return [0, 6].includes(date.getDay())
    }
  }
}
</script>

<style lang='scss' scoped>
::v-deep .el-calendar__header {
  display: none;
}

.flex {
  display: flex;
  justify-content: space-between;

  .rest {
    display: inline-block;
    width: 25px;
    height: 25px;
    background-color: red;
    border-radius: 50%;
    text-align: center;
    line-height: 25px;
    color: white;
  }
}

</style>
